import random
from time import sleep
import threading
x =1
p =x

def changev():
    while True:
        sleep(5)

        global x,p
        x = random.randint (1, 10)
        print('线程随机获取值x=',x)



t1= threading.Thread(target=changev)
t1.start()

print('主线程开始')
while True:
    sleep(1)
    if p !=x:
        p = x
        print('x发生变话',x,p)